package com.atguigu.day16.collectiontest;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @author fenge
 */
public class Test02 {
    public static void main(String[] args) {
        ArrayList<Student> arrayList = new ArrayList<>();
        Scanner s = new Scanner(System.in);
        boolean exit = true;
        while (exit) {
            System.out.println("选择(1、录入:0、退出):");
            int first = s.nextInt();
            if (first == 1) {
                System.out.println("姓名:");
                Student student = new Student();
                student.setName(s.next());
                System.out.println("年龄:");
                student.setAge(s.nextInt());
                arrayList.add(student);
            } else if (first == 0)
                exit = false;
            else
                System.out.println("输入有误请重新输入!");
        }
        Iterator iterator = arrayList.iterator();
        for (Student student : arrayList) {
            System.out.println(iterator.next().toString());
        }
    }
}
